package com.jump.userweb.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.net.HttpCookie;
import java.util.Map;
import java.util.UUID;

/**
 * Created by fangxiao on 15/9/10.
 */
public class Util {


    private static final String SUCCESS = "000000";

    public static void handleWebUser(HttpSession session, HttpServletResponse response, Map resMap ) {
        String resCode = (String)resMap.get("resCode");
        if(SUCCESS.equals(resCode)) {
            Map userMap = (Map) resMap.get("userMap");
            String userName = (String)userMap.get("userName");
            session.setAttribute("userName", userName);
            session.setMaxInactiveInterval(15 * 60);
            Cookie cookie = new Cookie("_g", UUID.randomUUID().toString());
            response.addCookie(cookie);
        }
    }

    public static boolean isSessionValid(HttpSession session) {
        String userName = (String)session.getAttribute("userName");
        if(userName == null)
            return false;
        return true;
    }



}
